package com.example.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionUtils {

    private static final ConnectionFactory connectionFactory = new ConnectionFactory();

    static {
        connectionFactory.setVirtualHost("/");
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("123456");
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
    }

    public static Connection openConnection(String name) throws IOException, TimeoutException {
        return (name == null)
                ? connectionFactory.newConnection()
                : connectionFactory.newConnection(name);
    }
}
